#!/bin/bash
funcs=`which functions.sh`
if [ "$funcs" != "" ] 
then
    . $funcs
fi 

#需要安装的文件列表
file_list="tftp tftpd xinetd"
#是否重新设置tftp服务器
should_set_tftp=false
for i in $file_list
do	
if ! dpkg_status $i ; then
    should_set_tftp=true
fi
done

if [ "$funcs" = "" ] 
then
    sudo apt-get install $file_list
else
    dpkg_install $file_list
fi 

if [ $should_set_tftp = "false" ] ; then
    exit
fi 

echoColor "＊＊＊＊设置tftp服务器" GREEN
cat >~/tftp_config<<EOF
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
EOF
sudo cp ~/tftp_config  /etc/xinetd.d/tftp -rf
rm ~/tftp_config
sudo mkdir /tftpboot -p
sudo chown -R $USER.$USER /tftpboot
sudo /etc/init.d/xinetd restart
